<?
/*
    This collection of functions (libary) is licensed under GPL2.
    See LICENSE or www.gnu.org for more details.

    Author Henri Ranki 26.10.2001

    $Id: dzfeaturespool.php 595 2006-04-03 16:00:47Z jyry $
*/

include_once("sodebug.php");
include_once("sostring.php");
include_once("soset.php");
include_once("dzconst.php");
include_once("sogeneric.php");

/** Class for storing scripting attributes.
 *  Class to store scripting attributes. This information is used when
 *  producing script in dzAsm class.
 *
 *  Class contains one base property that is type of soSet. It holds all the
 *  data. This class also introduces some access methods that should be used
 *  when provided. The keys to the attributes are defined in dzconst.php.
 *  @var soSet $__Data Attribute information. The key to the attributes are defined in
 *      dzconst.php
 */
class dzScriptFeatureSpool {

    /* Private section */
    var $__Data;


    /** Constructor
     */
    function dzScriptFeatureSpool() {
        $this->__Data = new soSet();
    } // dzScriptFeatureSpool


    /** Get the attribute with the given key.
     *  Use this when no access function is provided.
     *  @param string $Key Key to the attribute
     */
    function getAttrib($Key) {
        return $this->__Data->getItem($Key);
    } // getAttrib


    /** Sets a value for an attribute.
     *  Assign the given value to a specified key. Use this if no access
     *  function is provided.
     *  @param string $Key Key to the attribute
     *  @param string $value Attribute to assign to the key
     */
    function setAttrib($Key, $Value) {
        $this->__Data->setItem($Key, $Value);
    } // setAttrib


    /** Get the array of the names of the used widgets
     *  @return array/string
     */
    function getUsedWidgets() {
        $value = $this->__Data->getItem(DZSA_USED_WIDGETS);
        if (soGetClass($value) == "soset")
            $result = $value->getKeys();
        else
            $result = array();
        return $result;
    } // getUsedWidgets


    /** Add the type of the required widget to the set of the used widgets
     *  @param string $Type The type of the widget
     */
    function addToUsedWidgets($Type) {
        $value = $this->__Data->getItem(DZSA_USED_WIDGETS);
        if (soGetClass($value) != "soset") $value = new soSet();
        $value->addItem($Type);
        $this->__Data->setItem(DZSA_USED_WIDGETS, $value);
    } // addToUsedWidgets


    /** Return the required features
     *  @return array/string Names of the required features
     */
    function getReqFeatures() {
        $result = $this->__Data->getItem(DZSA_REQ_FEATURES);
        return $result->getKeys();
    } // getReqFeatures


    /** Add a set of features to required features
     *  @param object soSet/string $Features Set of the required features
     *      to add
     */
    function addToReqFeatures($Features) {
        $value = $this->__Data->getItem(DZSA_REQ_FEATURES);
        if (soGetClass($value) != "soset") $value = new soSet();
        $value->joinSet($Features);
        $this->__Data->setItem(DZSA_REQ_FEATURES, $value);
    } // addToReqFeatures


    /** Adds required features to generic script set.
     *  Features inserted to this set are inserted into head script.
     *  @param string $FeatureList String containing the features to insert
     *      into the general feature set. The features are space delimited.
     */
    function addGenFeatures($FeatureList) {
        $value = $this->__Data->getItem(DZSA_GEN_FEATURES);
        if (soGetClass($value) != "soset") $value = new soSet();
        $value->joinArrayAsKeys(soExplode($FeatureList, " "));
        $this->__Data->setItem(DZSA_GEN_FEATURES, $value);
    } // addGenFeatures


    /** Checks if the defined ini action is already set
     *  @param int $Action Init action type
     */
    function isInitAction($Action) {
        $value = $this->__Data->getItem(DZSA_INIT_ACTION);
        if (soGetClass($value) == "soset") {
            $result = $value->itemExists($Action);
        } else {
            $result = 0;
        }; // else if

        return $result;
    } // isInitAction


    /** Add action to initialization of the form
     *  @param int $Action Init action type
     *  @param array||string $Parameters Parameters for the action. If a non
     *  array value is passed, it is converted to array($parameters).
     */
    function setInitAction($Action, $Parameters) {
        if (!is_array($Parameters)) $Parameters = array($Parameters);
        $value = $this->__Data->getItem(DZSA_INIT_ACTION);
        if (soGetClass($value) != "soset") $value = new soSet();
        $value->setItem($Action, $Parameters, 1);
        $this->__Data->setItem(DZSA_INIT_ACTION, $value);
    } // setInitAction


} // dzScriptFeatureSpool
?>
